package cn.edu.bnu.bnuboy.xiaohua;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import android.app.Activity;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;

public class StrangeWordsActivity extends Activity implements OnItemClickListener{
	SQLiteDatabase db;
	Cursor c;
	ListView lv;
	TextView tv;
	int count;
	ArrayList<String> enwordlist = new ArrayList<String>();
	ArrayList<String> cnwordlist = new ArrayList<String>();
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.strangewords);
		lv = (ListView) this.findViewById(R.id.strangewordslist);
		tv = (TextView) this.findViewById(R.id.cn);
		try {
			db = this.openOrCreateDatabase("gre",SQLiteDatabase.OPEN_READWRITE, null);
		} catch (Exception e) {
			db.close();
			e.printStackTrace();
		}
		try{
			c = db.rawQuery("select distinct(*) from strangewordsview",null);
			count = c.getCount();
			if(count < 1){
				tv.setText("��ʱ�û�����");
				c.close();
				db.close();
				return;
			}
			while(c.moveToNext()){
				String id = c.getString(0);
				String en = c.getString(1);
				String cn = c.getString(2);
				enwordlist.add(en);
				cnwordlist.add(cn);
			}
			String[] enstrs = enwordlist.toArray(new String[0]);
			String[] cnstrs = cnwordlist.toArray(new String[0]);
			ArrayAdapter<String> ad = new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1, enstrs);
			lv.setAdapter(ad);
			lv.setOnItemClickListener(this);
		}catch(Exception e){
			e.printStackTrace();
		}
	}
	@Override
	public void onItemClick(AdapterView<?> arg0, View arg1, int pos, long arg3) {
		// TODO Auto-generated method stub
		tv.setText(cnwordlist.get(pos));
	}
	
}
